package com.buaa.hyf.util;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.util.Log;

import java.io.IOException;

/**
 * Created by hyf on 2016/4/23.
 */
public class ImageUtil {

    private static Bitmap uiMain;
    public static Bitmap topStart;
    private static Bitmap topBar;
    private static Bitmap canSelect;
    private static Bitmap noSelect;

    public static void init(Activity a) throws IOException {

        uiMain = BitmapFactory.decodeStream(a.getAssets().open("ui_main.png"));

        topStart = getImagePiece(1020, 1939, 108, 108);
        topBar = getImagePiece(975,893,640,96);
        canSelect = getImagePiece(975,338,74,76);
        noSelect = getImagePiece(1602, 155, 66, 63);

    }

    //切图
    public static Bitmap getImagePiece(int x,int y,int width,int height){
        Log.i("ss","star................");
        return Bitmap.createBitmap(uiMain,x,y,width,height);
    }

    //缩放
    public static Bitmap getScaleImagePiece(Bitmap source,int overWidth,int overHeight){
        Matrix m = new Matrix();
        m.postScale(overWidth / source.getWidth(), overHeight / source.getHeight());
        return Bitmap.createBitmap(source,0,0,source.getWidth(),source.getHeight());
    }

    //旋转
    public static Bitmap getRotateImagePiece(Bitmap source){
        Matrix m = new Matrix();
        m.postRotate(25,source.getWidth()/2,source.getHeight()/5);
        return Bitmap.createBitmap(source,0,0,source.getWidth(),source.getHeight());
    }

    public static Bitmap getTopStart() {
        return topStart;
    }

    public static Bitmap getTopBar() {
        return topBar;
    }

    public static Bitmap getNoSelect() {
        return noSelect;
    }

    public static Bitmap getCanSelect() {
        return canSelect;
    }
}
